using System;
using System.ComponentModel;

namespace FluentBinding.WinForms.Domain
{
    public class Country : INotifyPropertyChanged
    {
        #region Fields

        private City _city;
        private string _code;
        private string _name;

        #endregion

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged = delegate { };

        #endregion

        #region Testing backdoor

        public Delegate[] GetPropertyChangedInvocationList()
        {
            return PropertyChanged.GetInvocationList();
        }

        #endregion

        #region Public properties

        public string Name
        {
            get { return _name; }
            set
            {
                if (_name != value)
                {
                    _name = value;
                    PropertyChanged(this, new PropertyChangedEventArgs("Name"));
                }
            }
        }

        public City City
        {
            get { return _city; }
            set
            {
                if (_city != value)
                {
                    _city = value;
                    PropertyChanged(this, new PropertyChangedEventArgs("City"));
                }
            }
        }

        public string Code
        {
            get { return _code; }
            set
            {
                if (_code != value)
                {
                    _code = value;
                    PropertyChanged(this, new PropertyChangedEventArgs("Code"));
                }
            }
        }

        #endregion

        #region Public methods

        public override string ToString()
        {
            return Name ?? ToString();
        }

        #endregion
    }
}